import React from 'react'
import { Layout,Image} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import "./tr.css"
import {useSelector,useDispatch,connect} from 'react-redux'

const {Content} = Layout;

const SchoolRecruit = () => {
  const recruitList = useSelector(state=> state.recruit.recruitList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()
  const columns = [
    {
      title: '学校名称',
      key: 'school_name',
      dataIndex: 'school_name',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '招生简章',
        key: 'recruit_content',
        dataIndex: 'recruit_content',
        valueType: 'text',
        ellipsis:true
    },
    {
      title: '城市',
      key: 'school_city',
      dataIndex: 'school_city',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={interest} url='http://101.34.58.111:8081/schoolrecruit'/></div>
        , <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://101.34.58.111:8081/schoolrecruit/${record.school_name}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          }
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];

    const right = {}

    const interest = [
      {name:'school_name',label:'学校名称',tooltip:'最长为24位',placeholder:'输入学校名称'},
      {name:'recruit_content',label:'招生简章',placeholder:'输入招生简章'},
      {name:'school_city',label:'学校地点',tooltip:'最长为24位',placeholder:'请输入学校地点'}
    ]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280}}>
          <Table title="学校招生简章管理" columns={columns} right={right} url="http://101.34.58.111:8081/schoolrecruit" ques={interest}/>
        </Content>
    )
}

export default connect()(SchoolRecruit)
